﻿var groupListTableVue = new Vue({
    el: "#groupListTable",
    data: {
        groupList: []
    },
    methods: {
        AddGroup: function () {
            AddGroupDetail(this);
        },
        EditGroup: function (group) {
            EditGroupDetail(this, group);
        },
        DeleteGroup: function (group) {
            DeleteGroupDetail(this, group);
        }
    },
    created: function () {
        //页面加载前初始的数据
        InitialAztechScript();
    },
    mounted: function () {
        //页面加载后初始的数据
        ListGroup(this);
    }
});

/**
 * 查询所有用户组信息
 */
function ListGroup(vue) {
    ShowAzLoading();
    $.ajax({
        type: "GET",
        url: "/Account/ListGroup?v=" + Math.random(),
        success: function (res) {
            if (res.status == "Success") {
                vue.groupList = res.data;
            } else {
                toastr.error(res.message);
            }
            HideAzLoading();
        },
        error: function (err) {
            console.log(err);
            toastr.error("服务器发生错误，请稍候再试An error occurred in the server. Please try again later。");
            HideAzLoading();
        }
    })
}

/**
 * 增加用户组信息
 */
function AddGroupDetail(vue) {
    OpenAzModal("新增用户组Add user group", "/Account/GroupDetail?IsNew=true", function () {
        ListGroup(vue);
    });
}

/**
 * 编辑用户组信息
 */
function EditGroupDetail(vue, group) {
    OpenAzModal("编辑用户组Edit user group", "/Account/GroupDetail?GroupID=" + group.ID, function () {
        ListGroup(vue);
    });
}

/**
 * 删除用户组信息
 */
function DeleteGroupDetail(vue, group) {
    var message = "确认删除用户组Confirm deletion of user group【" + group.Name + "】?";
    if (confirm(message)) {
        ShowAzLoading();
        $.ajax({
            type: "POST",
            url: "/Account/DeleteGroup",
            data: { GroupID: group.ID },
            success: function (res) {
                if (res.status == "Success") {
                    toastr.success("删除用户组信息成功User group information deleted successfully。");
                    ListGroup(vue);
                } else {
                    toastr.error(res.message);
                }
                HideAzLoading();
            },
            error: function (err) {
                console.log(err);
                toastr.error("服务器发生错误，请稍候再试An error occurred in the server. Please try again later。");
                HideAzLoading();
            }

        })
    }
}